              package com.java.diagnostics.visualizer.impl.data;
              
              import com.java.diagnostics.visualizer.data.DataPoint;
              import com.java.diagnostics.visualizer.data.axes.AxisPair;
              import com.java.diagnostics.visualizer.impl.axes.DataAxisImpl;
              import java.text.MessageFormat;
              
              public class DataPointImpl
                implements DataPoint, Comparable
              {
                private static final String TO_STRING_TEMPLATE = "({0} {1}, {2} {3})";
                private static final String TO_RAW_STRING_TEMPLATE = "({0, number}, {1, number}))";
                private static final MessageFormat toStringFormatter = new MessageFormat(
                  "({0} {1}, {2} {3})");
              
                private String comment = "({0, number}, {1, number}))";
                private double x;
                private double y;
                private int sequenceUID = 0;
                private final DataAxisImpl xAxis;
                private final DataAxisImpl yAxis;
                private static String previousComment;
              
                public DataPointImpl(int sequenceUID, double x, double y, String comment, AxisPair axisPair)
                {
                  this.sequenceUID = sequenceUID;
                  this.x = x;
                  this.y = y;
                  this.xAxis = ((DataAxisImpl)axisPair.getXAxis());
                  this.yAxis = ((DataAxisImpl)axisPair.getYAxis());
              
                  if (comment != null)
                    if (comment.equals(previousComment)) {
                      this.comment = previousComment;
                    }
                    else {
                      this.comment = comment;
                      previousComment = comment;
                    }
                }
              
                public double getX(String units)
                {
                  return this.xAxis.convert(this, units);
                }
              
                public double getY(String units) {
                  return this.yAxis.convert(this, units);
                }
              
                public String formatX(String units) {
                  return this.xAxis.format(this, units);
                }
              
                public String formatY(String units) {
                  return this.yAxis.format(this, units);
                }
              
                public String formatXWithUnits(String units) {
                  return this.xAxis.formatWithUnits(this, units);
                }
              
                public String formatYWithUnits(String units) {
                  return this.yAxis.formatWithUnits(this, units);
                }
              
                public double getRawX() {
                  return this.x;
                }
              
                public double getRawY() {
                  return this.y;
                }
              
                public String getComment() {
                  return this.comment;
                }
              
                public void setComment(String comment) {
                  this.comment = comment;
                }
              
                public String toString() {
                  Object[] toStringArray = { formatX(this.xAxis.getUnits()), 
                    this.xAxis.getUnits(), formatY(this.yAxis.getUnits()), this.yAxis.getUnits() };
              
                  return toStringFormatter.format(toStringArray);
                }
              
                public String toRawString()
                {
                  Object[] toStringArray = { new Double(getRawX()), 
                    new Double(getRawY()) };
              
                  return MessageFormat.format("({0, number}, {1, number}))", toStringArray);
                }
              
                public int getSequenceUID()
                {
                  return this.sequenceUID;
                }
              
                public int compareTo(Object o) {
                  if (!(o instanceof DataPointImpl)) {
                    return 0;
                  }
              
                  DataPointImpl dp = (DataPointImpl)o;
                  Double xValue1 = Double.valueOf(dp.getRawX());
                  Double xValue2 = Double.valueOf(getRawX());
              
                  return xValue2.compareTo(xValue1);
                }
              }

